package org.md.budzik.problems;

import java.math.BigInteger;

/**
 * Obsługa dwumianu Newtona.
 * @author Wiezzel
 *
 */
public class Binomial extends TwoArgOp {
	
	public static BigInteger binom(BigInteger x, BigInteger y) throws ParseException {
		if (x.compareTo(y) < 0)
			throw new ParseException("Nie istnieje dwumian Newtona " + x + " po " + y);
		return Factorial.fact(x).divide(Factorial.fact(y).multiply(Factorial.fact(x.subtract(y))));
	}

	public Binomial(Expression ex2, Expression ex1) {
		super(ex2, ex1);
	}

	protected BigInteger computeOperation(BigInteger x, BigInteger y) throws ParseException {
		return binom(x, y);
	}

	protected String operationSymbol() {
		return "binom";
	}

}
